Skip to content

feat: add tab:newtablayout setting for custom new tab layouts#3117

Open
Wechat-ggGitHub wants to merge 1 commit intowavetermdev:mainfrom
Wechat-ggGitHub:feat/tab-newtablayout
Open

feat: add tab:newtablayout setting for custom new tab layouts#3117
Wechat-ggGitHub wants to merge 1 commit intowavetermdev:mainfrom
Wechat-ggGitHub:feat/tab-newtablayout

Conversation

@Wechat-ggGitHub
Copy link

Summary

  • Add tab:newtablayout setting that allows users to define a custom block layout for new tabs via settings.json
  • When not set, the default single-terminal layout is preserved (fully backward compatible)
  • Layout format reuses the existing PortableLayout structure used internally by Wave (same as GetStarterLayout())

Motivation

Currently, every new tab in Wave opens with a single terminal block. There is no way to configure a custom default layout. Users who want a consistent workflow (e.g., file browser + terminal side by side) must manually set up the layout each time. This is a frequently requested feature (e.g., #2057).

Example Usage

Add to ~/.config/waveterm/settings.json:

{
  "tab:newtablayout": [
    {
      "indexarr": [0],
      "blockdef": {
        "meta": {
          "view": "preview",
          "file": "~"
        }
      },
      "size": 20
    },
    {
      "indexarr": [1],
      "blockdef": {
        "meta": {
          "view": "term",
          "controller": "shell"
        }
      },
      "focused": true
    }
  ]
}

This creates a split layout with a file browser on the left (20% width) and a terminal on the right (focused by default).

Available view types for blockdef meta

  • term — Terminal (with optional controller: "shell")
  • preview — File browser (with file for initial directory)
  • web — Web view (with url for initial URL)
  • sysinfo — System info panel

How indexarr works

  • [0] — First child of root (left/top)
  • [1] — Second child of root (right/bottom)
  • [1, 1] — Second child of second child (nested split)
  • See GetStarterLayout() in pkg/wcore/layout.go for a 4-block example

Changes

  • schema/settings.json — Added JSON Schema definition for tab:newtablayout
  • pkg/wconfig/settingsconfig.go — Added TabNewTabLayout field to SettingsType
  • pkg/wcore/workspace.go — Added getNewTabLayoutFromConfig() and updated CreateTab() to use it

Test plan

  • Build and run Wave locally
  • Verify: without tab:newtablayout set, new tabs open with single terminal (unchanged behavior)
  • Verify: with tab:newtablayout set as shown above, new tabs open with file browser + terminal split
  • Verify: invalid layout JSON falls back to default single terminal
  • Verify: first-launch starter layout is unaffected

🤖 Generated with Claude Code

Allow users to define a custom block layout for new tabs via the
`tab:newtablayout` setting in settings.json. This enables use cases like
automatically opening a file browser alongside a terminal when creating
a new tab.

When not set, the default single-terminal layout is preserved.

Example configuration for files + terminal split:
{
  "tab:newtablayout": [
    {
      "indexarr": [0],
      "blockdef": {"meta": {"view": "preview", "file": "~"}},
      "size": 20
    },
    {
      "indexarr": [1],
      "blockdef": {"meta": {"view": "term", "controller": "shell"}},
      "focused": true
    }
  ]
}

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link

CLAassistant commented Mar 25, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 25, 2026

Walkthrough

This change introduces support for configurable default layouts when creating new tabs. A new TabNewTabLayout field is added to the settings configuration struct, a schema definition is provided to describe the layout structure, and helper logic is implemented to read this configuration and deserialize it into a PortableLayout for use when creating tabs, with fallback to the default layout if the configuration is invalid or empty.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly and concisely summarizes the main change: adding a new tab:newtablayout setting feature.
Description check ✅ Passed The description thoroughly explains the feature, motivation, implementation details, usage examples, and test plan—all directly related to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pkg/wcore/workspace.go (1)

199-214: Consider logging when configuration fallback occurs.

The function silently falls back to the default layout when the user's configuration is invalid or cannot be parsed. While this matches the intended behavior (graceful degradation), users may not realize their custom layout configuration is being ignored due to a syntax or structural error.

Adding a debug/warning log when fallback occurs would help users troubleshoot configuration issues:

💡 Suggested enhancement for debugging
 func getNewTabLayoutFromConfig() PortableLayout {
 	settings := wconfig.GetWatcher().GetFullConfig()
 	rawLayout := settings.Settings.TabNewTabLayout
 	if rawLayout != nil {
 		barr, err := json.Marshal(rawLayout)
-		if err == nil {
-			var layout PortableLayout
-			if json.Unmarshal(barr, &layout) == nil && len(layout) > 0 {
-				return layout
-			}
+		if err != nil {
+			log.Printf("warning: failed to marshal tab:newtablayout config: %v", err)
+		} else {
+			var layout PortableLayout
+			if err := json.Unmarshal(barr, &layout); err != nil {
+				log.Printf("warning: failed to parse tab:newtablayout config: %v", err)
+			} else if len(layout) > 0 {
+				return layout
+			} else {
+				log.Printf("warning: tab:newtablayout config is empty, using default")
+			}
 		}
 	}
 	return GetNewTabLayout()
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/wcore/workspace.go` around lines 199 - 214, The getNewTabLayoutFromConfig
function silently falls back to GetNewTabLayout() when
settings.Settings.TabNewTabLayout is nil/invalid/empty; update
getNewTabLayoutFromConfig to log a debug/warning whenever a fallback occurs,
including the error (from json.Marshal/json.Unmarshal) and the offending
rawLayout value so users can diagnose bad configs; reference the existing
symbols getNewTabLayoutFromConfig, PortableLayout, GetNewTabLayout, and
wconfig.GetWatcher().GetFullConfig and emit the log before returning the default
layout.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/wcore/workspace.go`:
- Around line 199-214: The getNewTabLayoutFromConfig function silently falls
back to GetNewTabLayout() when settings.Settings.TabNewTabLayout is
nil/invalid/empty; update getNewTabLayoutFromConfig to log a debug/warning
whenever a fallback occurs, including the error (from
json.Marshal/json.Unmarshal) and the offending rawLayout value so users can
diagnose bad configs; reference the existing symbols getNewTabLayoutFromConfig,
PortableLayout, GetNewTabLayout, and wconfig.GetWatcher().GetFullConfig and emit
the log before returning the default layout.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0390ecef-71ea-4aa2-b09b-448131ae3118

📥 Commits

Reviewing files that changed from the base of the PR and between 0ee1224 and c54c158.

📒 Files selected for processing (3)
  • pkg/wconfig/settingsconfig.go
  • pkg/wcore/workspace.go
  • schema/settings.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants